package svc

import (
	"github.com/zeromicro/go-zero/rest"
	"github.com/zeromicro/go-zero/zrpc"
	"xialou_platform/app/middleware"
	"xialou_platform/services/agent/rpc/agent"
	"xialou_platform/services/order/api/internal/config"
	"xialou_platform/services/order/rpc/order"
)

type ServiceContext struct {
	Config   config.Config
	Auth     rest.Middleware
	AuthJwt  rest.Middleware
	AgentRpc agent.Agent
	OrderRpc order.Order
}

func NewServiceContext(c config.Config) *ServiceContext {
	return &ServiceContext{
		Config:   c,
		Auth:     middleware.NewAuthMiddleware(c.Auth.AccessSecret).Handle,
		AuthJwt:  middleware.NewAuthJwtMiddleware().Handle,
		AgentRpc: agent.NewAgent(zrpc.MustNewClient(c.AgentRpc)),
		OrderRpc: order.NewOrder(zrpc.MustNewClient(c.OrderRpc)),
	}
}
